package interfazGrafica;

import java.io.Serializable;

import processing.core.PApplet;
import processing.core.PVector;

public class Particle implements Serializable {

	private static final long serialVersionUID = 1L;
	
	private PApplet parent;
	private PVector location;
	private PVector velocity;
	private PVector acceleration;
	private float lifespan;

	public Particle(PVector l, PApplet p) {
		parent=p;
		acceleration = new PVector(0,(float) 0.05);
		velocity = new PVector(parent.random(-2,2),0);
		location = l.get();
		lifespan = (float) 255.0;
	}

	public void run() {
		update();
		display();
	}

	// Method to update location
	public void update() {
		velocity.add(acceleration);
		location.add(velocity);
		lifespan -= 1.0;
	}

	// Method to display
	public void display() {
		parent.stroke(51,102,255);
		parent.fill(0,0,0);
		parent.ellipse(location.x,location.y,8,8);
	}

	// Is the particle still useful?
	public boolean isDead() {
		if (lifespan < 0.0) return true;
		else return false;
	}
}